package com.example.gameapplication.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.gameapplication.R;
import com.example.gameapplication.bean.ScoreDataBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class RecordAdapter extends RecyclerView.Adapter<RecordAdapter.RecordViewHolder> {
    Context context;
    List<ScoreDataBean> scoreDataBeans;

    public List<ScoreDataBean> getScoreDataBeans() {
        return scoreDataBeans;
    }

    public void setScoreDataBeans(List<ScoreDataBean> scoreDataBeans) {
        this.scoreDataBeans = scoreDataBeans;
        notifyDataSetChanged();
    }

    public RecordAdapter(Context context) {
        this.context = context;
    }

    @NonNull
    @Override
    public RecordViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new RecordViewHolder(LayoutInflater.from(context).inflate(R.layout.record_item, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull RecordViewHolder holder, int position) {
        holder.tv_score.setText(scoreDataBeans.get(position).getScore()+"");
        holder.tv_boss.setText(scoreDataBeans.get(position).getBoss()+"");
        holder.tv_big.setText(scoreDataBeans.get(position).getBig()+"");
        holder.tv_middle.setText(scoreDataBeans.get(position).getMiddle()+"");
        holder.tv_small.setText(scoreDataBeans.get(position).getSmall()+"");
    }

    @Override
    public int getItemCount() {
        return scoreDataBeans == null ? 0 : scoreDataBeans.size();
    }

    public class RecordViewHolder extends RecyclerView.ViewHolder {

        TextView tv_score;
        TextView tv_boss;
        TextView tv_big;
        TextView tv_middle;
        TextView tv_small;
        public RecordViewHolder(@NonNull View itemView) {
            super(itemView);
            tv_score=itemView.findViewById(R.id.tv_score);
            tv_boss=itemView.findViewById(R.id.tv_boss);
            tv_big=itemView.findViewById(R.id.tv_big);
            tv_middle=itemView.findViewById(R.id.tv_middle);
            tv_small=itemView.findViewById(R.id.tv_small);
        }
    }
}
